﻿
Imports storoomc
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl

Public Class validator
    Inherits requestProcessor

    Public Const _pathidentity As String = "/t"

    Public Overrides Function pathidentity() As String
        Return _pathidentity
    End Function

    Public Shared Function validate(ByVal rename As String, ByVal file As String, _
                                    Optional ByRef originalFilename As String = Nothing, _
                                    Optional ByRef key As String = Nothing) As Boolean
        If Not isemptystring(rename) Then
            copy(originalFilename, rename)
        ElseIf Not isemptystring(file) Then
            originalFilename = filename(file)
        End If

        If isemptystring(originalFilename) Then
            Return False
        Else
            key = generateStoroomKey(originalFilename)
            Return Not storoom.seek(key)
        End If
    End Function

    Public Shared Function validate(ByVal context As httpContext, Optional ByRef key As String = Nothing) As Boolean
        assert(Not context Is Nothing, "context is nothing.")
        Return validate(context.url().query(query.rename), context.url().query(query.file), key)
    End Function

    Public Overrides Function process(ByVal context As httpContext) As Boolean
        assert(Not context Is Nothing, "context is nothing.")
        If validate(context) Then
            context.writer().Write(context.string(stringId.VALIDATE_SUCCESSFUL))
        Else
            context.writer().Write(context.string(stringId.VALIDATE_FAILED))
        End If
    End Function
End Class
